
package com.joysuch.wwyt.core.bean;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import lombok.Data;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

//给前端返回的权限接口bean
@Data
@JsonInclude(value = Include.NON_NULL)
public class AuthorityBean {

    private Long id;
    private String url;
    private String name;
    private String label;
    private String icon;
    private Boolean selected;
    private int type;
    private List<AuthorityBean> children;

    // 业务流程引擎菜单所属流程ID
    private Long workFlowId;
    // 菜单Code传递一些参数
    private String code;
    // 主页快捷菜单图标
    private String dashboardIcon;

    // @JsonIgnore
    private Integer order;
    private String modelId;
    private Long inquiryId;
    //是否打开新窗口, 默认否 （0=否， 1=是）
    private Integer openNewWindow;

    // 权限
    private Set<AuthorityOperationBean> auth = new LinkedHashSet<>(0);

    public void addOperation(AuthorityOperationBean bean) {
        if (auth == null) {
            auth = new LinkedHashSet<AuthorityOperationBean>(5);
        }
        auth.add(bean);
    }

    public void addChild(AuthorityBean bean) {
        if (children == null) {
            children = new ArrayList<AuthorityBean>(5);
        }
        if (!children.contains(bean)) {
            children.add(bean);
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        AuthorityBean other = (AuthorityBean) obj;
        if (id == null) {
            if (other.id != null)
                return false;
        } else if (!id.equals(other.id))
            return false;
        return true;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }

}
